package com.ruoyi.web.controller.asset;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Assets;
import com.ruoyi.system.service.IAssetsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 管辖资产Controller
 *
 * @author ruoyi
 * @date 2025-08-17
 */
@Api(value = "管辖资产", tags = "管辖资产接口")
@RestController
@RequestMapping("/system/assets")
public class AssetsController extends BaseController
{
    @Autowired
    private IAssetsService assetsService;

    /**
     * 查询管辖资产列表
     */
    @PreAuthorize("@ss.hasPermi('system:assets:list')")
    @GetMapping("/list")
    public TableDataInfo list(Assets assets)
    {
        startPage();
        List<Assets> list = assetsService.selectAssetsList(assets);
        return getDataTable(list);
    }

    /**
     * 导出管辖资产列表
     */
    @PreAuthorize("@ss.hasPermi('system:assets:export')")
    @Log(title = "管辖资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Assets assets)
    {
        List<Assets> list = assetsService.selectAssetsList(assets);
        ExcelUtil<Assets> util = new ExcelUtil<Assets>(Assets.class);
        util.exportExcel(response, list, "管辖资产数据");
    }

    /**
     * 获取管辖资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:assets:query')")
    @GetMapping(value = "/{assetsId}")
    public AjaxResult getInfo(@PathVariable("assetsId") Long assetsId)
    {
        return success(assetsService.selectAssetsByAssetsId(assetsId));
    }

    /**
     * 新增管辖资产
     */
    @PreAuthorize("@ss.hasPermi('system:assets:add')")
    @Log(title = "管辖资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Assets assets)
    {
        return toAjax(assetsService.insertAssets(assets));
    }

    /**
     * 修改管辖资产
     */
    @PreAuthorize("@ss.hasPermi('system:assets:edit')")
    @Log(title = "管辖资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Assets assets)
    {
        return toAjax(assetsService.updateAssets(assets));
    }

    /**
     * 删除管辖资产
     */
    @PreAuthorize("@ss.hasPermi('system:assets:remove')")
    @Log(title = "管辖资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetsIds}")
    public AjaxResult remove(@PathVariable Long[] assetsIds)
    {
        return toAjax(assetsService.deleteAssetsByAssetsIds(assetsIds));
    }


    /**
     * 批量导入管辖资产
     */
    @ApiOperation(value = "批量导入管辖资产", notes = "上传Excel文件进行批量导入")
    @ApiImplicitParam(name = "file", value = "Excel文件", required = true, dataType = "MultipartFile", paramType = "form")
    @Log(title = "管辖资产", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
        ExcelUtil<Assets> util = new ExcelUtil<>(Assets.class);
        List<Assets> assetsList = util.importExcel(file.getInputStream());
        return assetsService.importAssets(assetsList);
    }
}
